package com.sysware.studio;

import java.util.Enumeration;
import java.util.Hashtable;

import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.widgets.Display;

public class ImageFactory {

	 
	private ImageFactory() {}
 
	private static Hashtable htImage = new Hashtable();
    
	public static Image loadImage(Display display, String imageName) {
		Image image = (Image) htImage.get(imageName.toUpperCase());
		if (image == null) {
			image = new Image(display, ImageFactory.class.getClassLoader().getResourceAsStream("/icons/"+imageName));
			htImage.put(imageName.toUpperCase(), image);
		}
		return image;
	}

	public static void dispose() {
		Enumeration e = htImage.elements();
		while (e.hasMoreElements()) {
			Image image = (Image) e.nextElement();
			if (!image.isDisposed())
				image.dispose();
		}
	}
}
